<?php

namespace app\admin\model;

use think\Model;


class Userminer extends Model
{

    

    

    // 表名
    protected $name = 'user_miner';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'virtual_text',
        'miner_cat_text',
        'miner_type_text',
        'buy_type_text',
        'status_text',
        'statistics_status_text',
        'endtime_text'
    ];
    

    
    public function getVirtualList()
    {
         return ['0' => __('Virtual 0'), '1' => __('Virtual 1')];
    }
    public function getMinerCatList()
    {
        return ['1' => __('Miner_cat 1'), '2' => __('Miner_cat 2'), '3' => __('Miner_cat 3')];
    }

    public function getMinerTypeList()
    {
        return ['1' => __('Miner_type 1'), '2' => __('Miner_type 2'), '3' => __('Miner_type 3')];
    }

    public function getBuyTypeList()
    {
        return ['1' => __('Buy_type 1'), '2' => __('Buy_type 2'), '3' => __('Buy_type 3'), '4' => __('Buy_type 4')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }

    public function getStatisticsStatusList()
    {
        return ['0' => __('Statistics_status 0'), '1' => __('Statistics_status 1')];
    }

    public function getVirtualTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['virtual']) ? $data['virtual'] : '');
        $list = $this->getVirtualList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getMinerCatTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['miner_cat']) ? $data['miner_cat'] : '');
        $list = $this->getMinerCatList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getMinerTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['miner_type']) ? $data['miner_type'] : '');
        $list = $this->getMinerTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBuyTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['buy_type']) ? $data['buy_type'] : '');
        $list = $this->getBuyTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatisticsStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['statistics_status']) ? $data['statistics_status'] : '');
        $list = $this->getStatisticsStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getEndtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setEndtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
